package com.wanwu.channel.remote.wxpay.convert;


import com.wanwu.channel.biz.context.DeclareContext;
import com.wanwu.channel.common.enums.PayType;
import com.wanwu.channel.dao.entity.ChannelApplyClearanceEntity;
import com.wanwu.channel.dao.entity.ChannelMerchantInfoEntity;
import com.wanwu.channel.remote.wxpay.config.WeixinGlobalConfig;
import com.wanwu.channel.remote.wxpay.http.WechatHttp;
import org.apache.commons.lang3.StringUtils;

/**
 * @author JiWen
 * @time 2020/3/26 23:48
 */
public class WeChatConvert {

    public static WechatHttp.DeclareCustomsReq toDeclareCustomsReq(DeclareContext context) {
        ChannelMerchantInfoEntity entity = context.getChannelMerchantInfoEntity();
        ChannelApplyClearanceEntity clearanceEntity = context.getApplyClearanceEntity();
        WechatHttp.DeclareCustomsReq req = new WechatHttp.DeclareCustomsReq();
        req.setChannelMerchantInfoEntity(entity);
        req.setAppId(null == entity ? context.getAppId() : entity.getMerchantAppId());
        req.setMchId(null == entity ? context.getMchId() : entity.getMerchantNo());
        req.setTransactionId(clearanceEntity.getThirdOrderNo());
        req.setOutTradeNo(clearanceEntity.getBizOrderNo());
        req.setCustoms(clearanceEntity.getCustomsPlace());
        req.setMchCustomsNo(clearanceEntity.getMerchantCustomsNo());
        req.setDuty(clearanceEntity.getDuty());
        req.setActionType(clearanceEntity.getActionTyep());

        req.setSubOrderNo(clearanceEntity.getSubOrderNo());
        req.setFeeType(clearanceEntity.getCurrency());
        req.setOrderFee(clearanceEntity.getSubOrderAmount());
        req.setTransportFee(clearanceEntity.getTransportAmount());
        req.setProductFee(clearanceEntity.getProductAmount());

        req.setCertType("IDCARD"); // 微信只支持大陆身份证
        req.setCertId(clearanceEntity.getCertId());
        req.setName(clearanceEntity.getCertName());
        if (StringUtils.isNotBlank(clearanceEntity.getActionTyep())){
            req.setActionType(clearanceEntity.getActionTyep());
        }

        return req;
    }

    public static WechatHttp.DeclareCustomsQryReq toDeclareCustomsQryReq(DeclareContext context){
        ChannelMerchantInfoEntity entity = context.getChannelMerchantInfoEntity();
        WechatHttp.DeclareCustomsQryReq req = new WechatHttp.DeclareCustomsQryReq();
        ChannelApplyClearanceEntity clearanceEntity = context.getApplyClearanceEntity();
        req.setChannelMerchantInfoEntity(entity);
        req.setAppId(null == entity ? context.getAppId() : entity.getMerchantAppId());
        req.setMchId(null == entity ? context.getMchId() : entity.getMerchantNo());
        req.setSubOrderNo(clearanceEntity.getSubOrderNo());
        req.setCustoms(clearanceEntity.getCustomsPlace());
        return req;
    }

    public static WechatHttp.DeclareCustomsResendReq toDeclareCustomsResendReq(DeclareContext context){
        ChannelMerchantInfoEntity entity = context.getChannelMerchantInfoEntity();
        ChannelApplyClearanceEntity clearanceEntity = context.getApplyClearanceEntity();
        WechatHttp.DeclareCustomsResendReq req = new WechatHttp.DeclareCustomsResendReq();
        req.setChannelMerchantInfoEntity(entity);
        req.setAppId(null == entity ? context.getAppId() : entity.getMerchantAppId());
        req.setMchId(null == entity ? context.getMchId() : entity.getMerchantNo());
        req.setTransactionId(clearanceEntity.getThirdOrderNo());
        req.setSubOrderId(clearanceEntity.getThirdSubOrderNo());
        req.setSubOrderNo(clearanceEntity.getSubOrderNo());
        req.setCustoms(clearanceEntity.getCustomsPlace());
        req.setMchCustomsNo(clearanceEntity.getMerchantCustomsNo());
        return req;
    }
}
